import { SET_CABINETID, GET_USERWALLET_RESOLVE, GET_USERWALLET_REJECT, GET_USERWALLET_PENDING, SET_LOCATIONDETAILVISIBLE } from './../constants/global';

const INITIAL_STATE = {
  cabinetId: '123',
  userWallet: [],
  userWalletPending: false,
  location: {
    visible: false,
    type: 'battery'
  }
}

export default function global (state = INITIAL_STATE, action) {
  switch(action.type) {
    case SET_CABINETID:
      return {
        ...state,
        // userWallet: [],
        cabinetId: action.cabinetId
      }
    case GET_USERWALLET_PENDING:
      return{
        ...state,
        userWalletPending: true
      }
    case GET_USERWALLET_RESOLVE:
      return {
        ...state,
        userWallet: action.userWallet,
        userWalletPending: false
      }
    case GET_USERWALLET_REJECT:
      return {
        ...state,
        userWallet: [],
        userWalletPending: false
      }
    case SET_LOCATIONDETAILVISIBLE:
      return {
        ...state,
        location: action.location
      }
    default:
      return state
      break
  }
}